# -*- coding: utf-8 -*-
import time

import execjs
import requests

from codes.commons.configs import easiest_common_headers as common_headers


def request_pages():
    sums = 0
    with open("../../resources/match16/w_trans.js", "r", encoding="utf-8") as fp:
        jscode = fp.read()

    ctx = execjs.compile(jscode)

    for i in range(1, 6):
        t = str(int(time.time() * 1000))
        m = ctx.call("btoa", t)
        params = {
            "m": m,
            "page": i,
            "t": t,
        }
        response = requests.get(url="http://match.yuanrenxue.com/api/match/16", params=params,
                                headers=common_headers).json()
        print(f'获取第【{i}】页数据：{response}')
        for each in response["data"]:
            sums += each["value"]
    print(sums)
    # 287383


if __name__ == "__main__":
    request_pages()
